/***********************************************
/gen auto by zuitools
***********************************************/

#include "entry/EasyUIContext.h"
#include "pointerActivity.h"
#include "control/ZKPointer.h"
#include "control/ZKSeekBar.h"
#include "control/ZKTextView.h"
#include "SystemUtils/DateTimes.h"
#include "control/ZKCircleBar.h"
/*register activity*/
REGISTER_ACTIVITY(pointerActivity);

static ZKPointer *m_pDirPointer1;
static ZKTextView* m_TextSpeed;
static ZKTextView* m_TextDir;
static ZKTextView* m_Time;
static ZKTextView* m_Date;
static ZKCircleBar* m_speedCircle;

static int mSpeed = 0;
static int mRotation = 0;

pointerActivity::pointerActivity() {
	//todo add init code here
}
pointerActivity::~pointerActivity() {
	//todo add init file here
}
const char* pointerActivity::getAppName() const{
	return "pointer.ftu";
}
void pointerActivity::onCreate() {
	//TODO: add create init code 
	Activity::onCreate();
	m_pDirPointer1 = (ZKPointer *) findControlByID(ID_POINTER_DASHBROADVIEW_2);

	m_TextDir = (ZKTextView*)findControlByID(ID_POINTER_LABEL_DIR);
	m_TextSpeed = (ZKTextView*)findControlByID(ID_POINTER_LABEL_SPEED);
	m_Time = (ZKTextView*)findControlByID(ID_POINTER_LABEL_TIME);
	m_Date = (ZKTextView*)findControlByID(ID_POINTER_LABEL_DATE);
	m_speedCircle = (ZKCircleBar*)findControlByID(ID_POINTER_CIRCLEBAR_1);
	char str[20] = { 0 };
	int ret = DateTimes::getTimeHMString(str);
	if(ret > 0){
		m_Time->setText(str);
	}
	memset(str,0,sizeof(str));
	ret = DateTimes::getDateYMDString(str);
	if(ret > 0){
		m_Date->setText(str);
	}

	//设置20ms的定时器用于动画显示
	registerTimer(0, 100);
	registerTimer(1, 100);
	registerTimer(2, 500);
}
void pointerActivity::onClick(ZKBase *pBase) {
	//TODO: add widget onClik code 
	Activity::onClick(pBase);
}

bool pointerActivity::onTimer(int id) {
	switch (id) {
	case 0:
		if (m_TextSpeed != NULL) {
			mSpeed += 8;
			if (mSpeed > 240) {
				mSpeed = 0;
			}
			char str[10] = { 0 };
			sprintf(str, "%d", mSpeed);
			m_TextSpeed->setText(str);

		}
		if (m_speedCircle != NULL) {
			m_speedCircle->setProgress(mSpeed);
		}
		break;
	case 1: {
		mRotation += 7;
		int value = mRotation;
		m_pDirPointer1->setTargetAngle(value);
		char str[10] = { 0 };
		if (value < 15 || value > 345) {
			sprintf(str, "%s", "正北");
		} else if (value < 75) {
			sprintf(str, "%s", "东北");
		} else if (value < 105) {
			sprintf(str, "%s", "正东");
		} else if (value < 165) {
			sprintf(str, "%s", "东南");
		} else if (value < 195) {
			sprintf(str, "%s", "正南");
		} else if (value < 255) {
			sprintf(str, "%s", "西南");
		} else if (value < 285) {
			sprintf(str, "%s", "正西");
		} else {
			sprintf(str, "%s", "西北");
		}
		m_TextDir->setText(str);
		break;
	}
	case 2: {
		char str[20] = { 0 };
		int ret = DateTimes::getTimeHMString(str);
		if (ret > 0) {
			m_Time->setText(str);
		}
		memset(str, 0, sizeof(str));
		ret = DateTimes::getDateYMDString(str);
		if (ret > 0) {
			m_Date->setText(str);
		}
	}
		break;
	}

	return true;
}
